package com.angel.bo.auth.server.controller;

import com.angel.bo.auth.client.annotation.IgnoreUserToken;
import com.angel.bo.auth.server.service.AuthService;
import com.angel.bo.beans.jwt.JwtInfo;
import com.angel.bo.beans.jwt.JwtLogin;
import com.angel.bo.common.msg.WebReturn;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: Haibo.Mei [Haibo.Mei@ge.com]
 * @Description:
 * @Date: 13:13 2018/1/30
 */
@RestController
@RequestMapping("jwt")
public class AuthController {

    @Autowired
    private AuthService authService;


    @ApiOperation(value = "用户登录，返回token信息",
            notes = "只有用户名密码正确才会返回token否则不返回",
            httpMethod = "POST",
            produces = "application/json",
            tags = "用户登录")
    @RequestMapping(value = "token", method = RequestMethod.POST)
    @IgnoreUserToken
    public WebReturn<String> createAuthenticationToken(@RequestBody JwtLogin jwtLogin){
        return authService.login(jwtLogin);
    }


    @RequestMapping(value = "user", method = RequestMethod.POST)
    @ApiOperation(value = "根据token获取用户信息",tags = "根据token获取用户信息")
    @IgnoreUserToken
    public WebReturn<JwtInfo> getUserInfo(@RequestBody String token) throws Exception {
        return authService.getUserAllInfo(token);
    }

}
